package com.webtest.demo;

import java.awt.Desktop.Action;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.openqa.selenium.WebDriver;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import com.webtest.core.WebTestListener2;



@Listeners({WebTestListener2.class})
public class CrossearthPageTest extends BaseDriver{
	
	CrossearthPage crossearthPage;
	
	@BeforeMethod
	public void init() throws InterruptedException {
		resetEmulatorState();
		crossearthPage=new CrossearthPage(driver);	
	}


	private void resetEmulatorState() {
		
	}
	
	private static void executeADBCommand(String command) {
		try{
			Process process = Runtime.getRuntime().exec(command);
	        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
	        String line;
	        while ((line = reader.readLine()) != null) {
	        	System.out.println(line);
	        }
	        process.waitFor();
	    }catch (IOException | InterruptedException e) {
	    	e.printStackTrace();
	    }
	}

	//一、忘记密码页面
	@Test(priority = 26,description = "不输入任何文本直接点击修改")	
	public void directlyclickreviseForgetPage() throws InterruptedException {
		//crossearthPage.enter();
		//crossearthPage.enter();
		crossearthPage.directlyclickRevise();
		crossearthPage.goback();
				
	}
	
	@Test(priority = 27,description = "输入错误的邮箱、合法新密码进行修改")	
	public void erroremailreviseForgetPage() throws InterruptedException {
		crossearthPage.erroremailRevise();	
		crossearthPage.goback();
	}
	
	@Test(priority = 28,description = "新密码为空、确认新密码不为空进行修改")	
	public void newpasswordemptyreviseForgetPage() throws InterruptedException {
		crossearthPage.newpasswordemptyRevise();
		crossearthPage.goback();
				
	}
	
	@Test(priority = 29,description = "邮箱及密码输入脚本函数进行修改")	
	public void scriptreviseForgetPage() throws InterruptedException {
		crossearthPage.scriptRevise();
		crossearthPage.goback();
				
	}
	
	@Test(priority = 30,description = "修改与原来相同的密码")	
	public void repeatpasswordreviseForgetPage() throws InterruptedException {
		crossearthPage.repeatpasswordRevise();
		crossearthPage.gohome();
				
	}

	//二、地图板块页面
	@Test(priority = 31,description = "进入夏朝涂山之会剧本，只选择第一个按钮")	
	public void xiameetingtumountainmapCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.xiameetingtumountainMap();
		crossearthPage.gohome();
	}
	
	@Test(priority = 32,description = "进入夏朝大禹治水剧本，插入查看朝代的步骤，接着下上按钮交替选择")	
	public void xiadayuwatermapCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.xiadayuwaterMap();
		crossearthPage.gohome();
	}
	
	@Test(priority = 33,description = "在夏朝剧情中进入商朝，然后返回主页面")	
	public void xiaentershangmapCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.xiaentershangMap();
		crossearthPage.gohome();
	}
	
	@Test(priority = 34,description = "进入商朝武丁中兴剧本，只选择最下面的按钮")	
	public void shangwudingmapCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.shangwudingMap();
		crossearthPage.gohome();
	}
	
	@Test(priority = 35,description = "进入商朝神道设教剧本前先点击牧野之战剧本，然后上下按钮交替选择")	
	public void shangbattlemakinomapCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.shangbattlemakinoMap();
		crossearthPage.gohome();
	}
	
	@Test(priority = 36,description = "在隋朝剧本中进入尉迟迥之乱前点击所有的剧本")	
	public void yuchirebellionmapCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.yuchirebellionMap();
		crossearthPage.gohome();
	}
	
	@Test(priority = 37,description = "在唐朝地图中不点击播放音乐，是否可以只调节音量的大小")	
	public void tangvolumeCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.tangvolumeMap();
		crossearthPage.gohome();
	}
	
	@Test(priority = 38,description = "在唐朝地图中先点击播放音乐，再点击暂停音乐")	
	public void tangplaypausemusicmapCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.tangplaypausemusicMap();
		crossearthPage.gohome();
	}
	
	@Test(priority = 39,description = "放大唐朝地图板块")	
	public void tangmagnifymapCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.tangmagnifyMap();
		crossearthPage.magnify();
		crossearthPage.gohome();
	}
	
	@Test(priority = 40,description = "在唐朝地图中多次点击播放音乐")	
	public void tangmultipletimesmusicmapCrossearth() throws InterruptedException {
		// ADB命令：清理后台       
        executeADBCommand("adb shell am force-stop com.software.crossearth");
        Thread.sleep(2000);
		crossearthPage.tangmultipletimesmusicMap();
		crossearthPage.gohome();
	}
	
	
//	public void adbCommand() throws InterruptedException {
//		//ADB命令：强制停止该应用     
//        executeADBCommand("adb shell am force-stop com.software.crossearth");
//        //ADB命令：设置屏幕密度为240
//        executeADBCommand("adb shell wm density 240");
//        //ADB命令：启动指定Activity 
//        executeADBCommand("adb shell am start -n com.software.crossearth/.MainActivity");
//        //ADB命令：设置显示比例
//        executeADBCommand("adb shell settings put global display_density_forced 2.4");
//        //ADB命令：重置屏幕大小，重新加载页面
//        executeADBCommand("adb shell wm size reset");
//   	    //ADB命令：恢复屏幕密度为默认值
//        executeADBCommand("adb shell wm density reset");      
//    	//ADB命令：删除显示比例设置
//        executeADBCommand("adb shell settings delete global display_density_forced");
//    	//ADB命令：重置屏幕大小，恢复初始页面设置
//        executeADBCommand("adb shell wm size reset");
//	}
	
}
